from ydata_profiling.report.presentation.flavours.html.frequency_table import (
    HTMLFrequencyTable,
)
from ydata_profiling.report.presentation.flavours.html.html import HTMLHTML
from ydata_profiling.report.presentation.flavours.html.image import HTMLImage


def test_html_frequency_table():
    item = HTMLFrequencyTable(
        rows=[{"count": 10, "percentage": 1.0, "label": "Pizza", "width": 1.0}],
        redact=False,
    )
    assert str(item) == "HTMLFrequencyTable"
    html = item.render()
    assert '<table class="freq table table-hover table-striped table-0">' in html


def test_html_html():
    test_str = "<strong>Blaat!</strong>"

    item = HTMLHTML(content=test_str)
    assert str(item) == "HTMLHTML"
    html = item.render()
    assert html == test_str


def test_html_image():
    image_str = ""
    caption_str = "Example Caption"
    alt_str = "Example Image"

    # Without caption
    item = HTMLImage(image=image_str, image_format="gif", alt=alt_str)
    assert str(item) == "HTMLImage"
    html = item.render()
    assert all(
        x in html
        for x in [
            f'src="{image_str}"',
            f'alt="{alt_str}"',
        ]
    )

    # With caption
    item_caption = HTMLImage(
        image=image_str, image_format="gif", alt=alt_str, caption=caption_str
    )
    assert str(item_caption) == "HTMLImage"
    html_caption = item_caption.render()
    assert all(
        x in html_caption
        for x in [
            f'src="{image_str}"',
            f'alt="{alt_str}"',
            caption_str,
        ]
    )
